<?php
	include_once 'index.model.php';
	
	class Membre {
		private $mail;
		private $nom;
		private $prenom;
		private $mdp;


		public static function getMembre($mail)
		{
			$connexion = connexion();
			$res = array();
			$select = $connexion->prepare('SELECT * FROM membre m WHERE m.mail = ?') or die(print_r($connexion->errorInfo()));
			$select->execute(array($mail));

			while($enregistrement = $select->fetch(PDO::FETCH_OBJ))
			{
				$res =new Membre($enregistrement->mail, $enregistrement->nom, $enregistrement->prenom, $enregistrement->mdp);
			}
			
			return $res;
		}


		public static function ajoutMembre($membre)
		{
			$connexion = connexion();
			$res = array();
			$select = $connexion->prepare('INSERT INTO membre (mail, nom, prenom, mdp) VALUES (?, ?, ?, ?)') or die(print_r($connexion->errorInfo()));
			$select->execute(array($membre->getMail(),$membre->getNom(),$membre->getPrenom(),$membre->getMdp()));
		}


		public function __construct($mail, $nom, $prenom, $mdp)
		{
			$this->mail = $mail;
			$this->nom = $nom;
			$this->prenom = $prenom;
			$this->mdp = $mdp;
		}

		public function getNom()
		{
			return $this->nom;
		}

		public function getPrenom()
		{
			return $this->prenom;
		}
		
		public function getMail()
		{
			return $this->mail;
		}

		public function getMdp()
		{
			return $this->mdp;
		}




		public function setNom($nom)
		{
			$this->nom = $nom;
		}

		public function setPrenom($prenom)
		{
			$this->prenom = $prenom;
		}
		
		public function setMail($mail)
		{
			$this->mail = $mail;
		}

		public function setMdp($mdp)
		{
			$this->mdp = $mdp;
		}


		public function setInfosMembre()
		{
			$connexion = connexion();
			$res = array();
			$select = $connexion->prepare('UPDATE membre SET mail=?, nom=?, prenom=?, mdp=? WHERE mail = ?') or die(print_r($connexion->errorInfo()));
			$select->execute(array($this->mail, $this->nom, $this->prenom, $this->mdp, $this->mail));
		}
	}
?>

